/**
 * 忘记密码
 * @author Qasim <15750783791@163.com>
 * @version 2016/9/5
 */
var self = '';

document.addEventListener('plusready' , ready ,  false);

function ready(){
	
	self = plus.webview.currentWebview();
	
	var phone = '';
	
	//获取验证码
	$('.verification').on('click' , function(){
		
		phone = $('input[name=phone]').val();
		
		if(!p1.test(phone)){
			
			toast('手机号码格式有误'); return;
			
		}
		
		checkUser(phone , 'forget_password');  
		
	})
	
	//找回密码
	$('.forget_pwd').on('tap' , function(){ 
		
		var pass = $('input[name=pass]').val() , 
		
			repass = $('input[name=repass]').val() , 
			
			verify = $('input[name=verification]').val() ,
			
			verify_local = plus.storage.getItem('verify');
		
		if(!phone){toast('没有获取到手机号'); return;} 
			
		if(!pass.trim() || !repass.trim()){ toast('密码不能为空'); return;}
		
		if(pass != repass){ toast('两次密码不一致'); return;}
		
		if(!verify.trim()){ toast('验证码不能为空'); return;}
		
		if(!verify_local || verify_local != verify){toast('验证码输入有误');return;}

		plus.nativeUI.showWaiting('请稍等...');
		
		$.ajax({
			
			url : apiRoot + '/Home/Member/forgetPassword/' , 
			
			type : 'post' , 
			
			data : {
				
				phone : phone , 
				
				pass : pass
				
			} , 
			
			success : function(data){
				
				plus.nativeUI.closeWaiting();
				
				plus.storage.removeItem('verify');
				
				if(data == 1 || data == 0){
					
					toast('找回密码成功');
					
					mui.fire(plus.webview.getWebviewById(self.self_window) , 'register' ,{
						
						'phone' : phone 
						
					})
					
					mui.back();
					
				}
				
			} , 
			error : function(e){
				
				plus.nativeUI.closeWaiting();
				
				toast('连接超时 ，请检查网络');
				
			}
		})
	})
	
}
